package com.example.hospital.service;

import com.example.hospital.common.PageResponse;
import com.example.hospital.domain.entity.DoctorSchedule;
import com.example.hospital.mapper.DoctorScheduleMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class DoctorScheduleService {
    private final DoctorScheduleMapper scheduleMapper;

    public DoctorScheduleService(DoctorScheduleMapper scheduleMapper) {

        this.scheduleMapper = scheduleMapper;
    }
    /**
     * 创建医生排班
     * @param s
     * @return
     */
    public DoctorSchedule create(DoctorSchedule s) {
        scheduleMapper.insert(s);
        return scheduleMapper.findById(s.getScheduleId()); }
    /**
     * 更新医生排班
     * @param s
     * @return
     */
    public boolean update(DoctorSchedule s) {
        return scheduleMapper.update(s) > 0;
    }
    /**
     * 删除医生排班
     * @param id
     * @return
     */
    public boolean delete(Long id) {
        return scheduleMapper.delete(id) > 0;
    }
    /**
     * 分页查询医生排班（按医生ID、排班日期筛选）
     * @param doctorId
     * @param date
     * @param page
     * @param size
     * @return
     */
    public PageResponse<DoctorSchedule> list(Long doctorId, LocalDate date, int page, int size) {
        int offset = (page - 1) * size;
        List<DoctorSchedule> list = scheduleMapper.list(doctorId, date, size, offset);
        long total = scheduleMapper.count(doctorId, date);
        return PageResponse.of(total, page, size, list);
    }
}